package com.frozendogtears.audiogame;

import java.util.List;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.echonest.api.v4.EchoNestException;
import com.echonest.api.v4.Song;

public class Game implements ApplicationListener {
	private EchoNest echoNest;
	private BitmapFont font;
	private SpriteBatch spriteBatch;
	private List<Song> songs;
	private String musicTitle = "everlong";
	private FileHandle musicFolder;
	
//	public Game(List<Song> songs)
//	{
//		this.songs = songs;
//	}
	
	@Override
	public void create() {
		
		try {
			echoNest = new EchoNest();
//			songs = echoNest.searchSongsByTitle(musicTitle, 10);
			songs = echoNest.searchSongsByArtist("Foo", 8);			
		} catch (Exception e) {
			
			System.out.print(e.getMessage());
		}
		spriteBatch = new SpriteBatch();
		
		musicFolder = new FileHandle(Gdx.files.getExternalStoragePath().concat("Music"));
		
		font = new BitmapFont(Gdx.files.internal("fonts/pressStartFont14.fnt"), false);		
		font.scale(0.1f);
		font.setColor(Color.YELLOW);
		
//		System.out.println(musicFolder.path());
		

//		System.out.print(musicTitle);
		
	}

	@Override
	public void resize(int width, int height) {
		
	}

	@Override
	public void render() {
		 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears
		 spriteBatch.begin();	
		 
//		 font.draw(spriteBatch, "test", 10, 400);		 
		 if(songs != null)
		 {
			 for(int i = 0; i < songs.size(); i++)
				 font.draw(spriteBatch, songs.get(i).getTitle().toString(), 10, (i+1) * 30);
		 }		 
		 
		 spriteBatch.end();		 
	}

	@Override
	public void pause() {

	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {

	}
}
